﻿/*
 * Created by SharpDevelop.
 * User: Heikki
 * Date: 21.11.2007
 * Time: 20:14
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace notebooklet
{
	/// <summary>
	/// Description of FilterList.
	/// </summary>
	public class FilterList : ListBox
	{
		private List<string> allItems;
		private List<string> filteredItems;
		private string keyword;
		
		public List<string> AllItems {
			get { return this.allItems; }
			set {
				this.allItems = value;
				filterResults();
			}
		}
		
		public string Keyword {
			get { return this.keyword; }
			set {
				this.keyword = value;
				filterResults();
			}
		}
		
		public FilterList() {
			// Ei käytetä propertyjä, koska niiden asettaminen
			// laukaisee filterResultsin.
			this.allItems = new List<string>();
			this.keyword = "";
			this.filterResults();
		}
		
		void filterResults() {
			if ( this.Keyword == "" ) {
				this.DataSource = this.allItems;
				return;
			}
			
			filteredItems = new List<string>();
			
			foreach ( string item in this.allItems ) {
				if ( item.IndexOf(this.keyword) != -1 ) {
					this.filteredItems.Add(item);
				}
			}
			
			this.DataSource = filteredItems;
		}
	}
}
